package com.icss.clothes.mapper;
import com.icss.clothes.entity.Remark;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RemarkMapper {
    //添加评论
    @Insert("insert into remark(user_id,c_id,remark_time,remark_content,remark_score,remark_picture)" +
            " values(#{user_id},#{c_id},now(),#{remark_content},#{remark_score},#{remark_picture})")
    public void addRemark(Remark remark);

    //通过用户id和商品id查询评论（查询是否用户已经评论过）
    @Select("select * from remark where user_id=#{user_id} and c_id=#{c_id}")
    public Remark selectRemarkByUidAndCid(Remark remark);

    //通过商品id查询评论
    @Select("select * from remark where c_id=#{c_id}")
    public List<Remark> selectRemarkByCid(int cid);

    //通过商品id查询评分
    @Select("select remark_score from commodity where c_id=#{c_id} ")
    public double selectScoreByCid(int cid);

    //通过商品id去更改评分
    @Update("update commodity set remark_score=#{remark_score}  where c_id=#{c_id}  ")
    public void updateScoreByCid(@Param("c_id") int c_id, @Param("remark_score") double remark_score);
}
